package pl.msikora.android.lapmagic.database;

import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

public class LocationsTable {
	
	private static final String TAG = "LocationsTable";
	
	public static final String TABLE_LOCATIONS = "locations";
	public static final String COLUMN_LAP_SESSION_ID = "lap_session_id";
	public static final String COLUMN_LAP_NO = "lap_no";
	public static final String COLUMN_LATITUDE = "latitude";
	public static final String COLUMN_LONGITUDE = "longitude";
	public static final String COLUMN_TIMESTAMP = "timestamp";
	public static final String COLUMN_SPEED = "speed";
	
	private static final String TABLE_CREATE = "create table "
			+ TABLE_LOCATIONS
			+ "("
			+ COLUMN_LAP_SESSION_ID + " integer not null, " // references laps on delete cascade
			+ COLUMN_LAP_NO + " integer not null, " // references laps on delete cascade
			+ COLUMN_LATITUDE + " integer not null, " // latitudeE6
			+ COLUMN_LONGITUDE + " integer not null, " // longitudeE6
			+ COLUMN_TIMESTAMP + " integer not null, " // in milliseconds
			+ COLUMN_SPEED + " integer not null" // kph
			+ ");";
	
	public static void onCreate(SQLiteDatabase database) {
		Log.d(TAG, "creating table locations with statement '" + TABLE_CREATE
				+ "'");
		database.execSQL(TABLE_CREATE);
	}
	
	public static void onUpgrade(SQLiteDatabase database, int oldVersion, 
			int newVersion) {
		Log.w(TAG, "Upgrading database from version " + oldVersion
				+ " to " + newVersion 
				+ ", which will destroy new all old data");
		database.execSQL("drop table if exists " + TABLE_LOCATIONS);
		onCreate(database);
	}

}
